package com.yq.spbYq.mapper;

import com.yq.spbYq.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    // 根据用户名查询用户
    @Select("SELECT * FROM wasteusrlog WHERE username = #{username}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "captcha", column = "captcha")
    })
    User selectByUsername(String username);

    // 查询所有用户
    @Select("SELECT * FROM wasteusrlog")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "captcha", column = "captcha")
    })
    List<User> selectAllUsers();

    // 新增用户
    @Insert("INSERT INTO wasteusrlog(username, password, captcha) VALUES(#{username}, #{password}, #{captcha})")
    int insertUser(User user);

    // 根据用户名删除用户
    @Delete("DELETE FROM wasteusrlog WHERE username = #{username}")
    int deleteUserByUsername(String username);

    // 更新用户信息
    @Update("UPDATE wasteusrlog SET password = #{password}, captcha = #{captcha} WHERE username = #{username}")
    int updateUser(User user);
    // 查询所有账户
    @Select("SELECT * FROM wasteusrlog")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "captcha", column = "captcha")
    })
    List<User> selectAllAccounts();
}